<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="Referrer" content="origin" />
<?php
global $set;
if ($set['code']['headcode'] != null) {
  echo base64_decode($set['code']['headcode']);
}

if ($set['code']['alifront'] != null) {
  echo '<style>.icon {width: 18px; height: 18px;vertical-align: -3px;fill: currentColor;overflow: hidden;}</style>';
}

if ($set['theme']['bagimg'] != null) {
  if (!is_page_template('page-login.php') && !is_page_template('page-reg.php')) {
    $bgsize = $set['theme']['bagimg_showtype'] == 1 ? 'background-size: cover;' : '';
    echo "<style>html, body, #app {background-image: url('{$set['theme']['bagimg']}')!important;background-position: center center;background-attachment: fixed;$bgsize}</style>";
  }
}

if ($set['routine']['favicon'] != null) {
  echo '<link rel="icon" href="' . $set['routine']['favicon'] . '" type="image/x-icon" />';
}
?>
<style>
  :root {
    --Maincolor: <?php echo $set['theme']['themeColor'] ?> !important;
    --MaincolorHover: <?php echo $set['theme']['themeHoverColor'] ?> !important;
    --fontSelectedColor: <?php echo $set['theme']['fontSelectedColor'] ?> !important;
  }

  #nprogress .bar {
    background: var(--Maincolor) !important;
  }
</style>
<?php
if ($set['module']['preventred'] == 1) {
  if (is_wx_qq()) {
    get_template_part('component/page-preventred');
    die();
  }
}

if ($set['theme']['font'] != 'no') {
  $ln = $set['optimization']['themecdnurl'] != '' ? $set['optimization']['themecdnurl'] : 'https://xy-cdn.lovestu.com/corepress';
  echo '<link rel="stylesheet" type="text/css" href="' . $ln . '/static/lib/font/' . $set['theme']['font'] . '/font.css">';
?>
  <style>
    html,
    textarea {
      font-family: <?php echo $set['theme']['font'] ?>, PingFang\ SC, Hiragino\ Sans\ GB, Microsoft\ YaHei, STHeiti, WenQuanYi\ Micro\ Hei, Helvetica, Arial, sans-serif !important;
    }
  </style>
  <?php
}

file_load_css('main-mobile.css');
loadiconfont_by_cdn();
file_load_css('main.css');

wp_head();

if ($set['theme']['loadbar'] == 1) {
  echo '<link href="' . CDN_PATH_BOOTCDN . '/nprogress/0.2.0/nprogress.min.css" rel="stylesheet"><script src="' . CDN_PATH_BOOTCDN . '/nprogress/0.2.0/nprogress.min.js"></script>';
}
if ($set['theme']['refurbish'] == 1) {
  file_load_js('jquery.pjax.min.js');
}
if ($set['code']['css'] != null) {
  echo "<style>" . base64_decode($set['code']['css']) . "</style>";
}
if (is_home()) {
  echo '<link href="' . CDN_PATH_BOOTCDN . '/Swiper/5.4.5/css/swiper.min.css" rel="stylesheet"><script async src="' . CDN_PATH_BOOTCDN . '/Swiper/5.4.5/js/swiper.min.js"></script>';
}
global $set;
if (is_home()) {
  if ($set['seo']['openseo'] == 1) {
    if ($set['seo']['indextitle'] != '') {
      $title = $set['seo']['indextitle'];
    } else {
      $title = get_bloginfo('name');
    }
  } else {
    $title = get_bloginfo('name');
  }
} elseif (is_single() || is_page()) {
  if ($set['post']['imgradius'] == 1) {
  ?>
    <style>
      .post-content-post img {
        border-radius: 10px;
      }
    </style>
  <?php
  }
  if ($set['post']['imgshadow'] == 1) {
  ?>
    <style>
      .post-content-content img {
        box-shadow: 0 0 5px 0 rgba(0, 0, 0, .1);
      }
    </style>
    <?php
  }

  file_load_css('comment-module.css');
  file_load_css('post-content.css');
  echo '<link href="' . CDN_PATH_BOOTCDN . '/fancybox/3.5.7/jquery.fancybox.min.css" rel="stylesheet"><script defer src="' . CDN_PATH_BOOTCDN . '/fancybox/3.5.7/jquery.fancybox.min.js"></script>';

  if ($set['module']['highlight'] == 1) {
    echo '<script defer src="' . CDN_PATH_BOOTCDN . '/highlight.js/11.7.0/highlight.min.js"></script>';
    $sty = $set['module']['highlighttheme'] == 1 ? 'corepress-dark' : 'corepress';
    file_load_lib('highlight/style/' . $sty . '.css', 'css');
  }

  if ($set['seo']['openseo'] == 1) {
    $delimiter = $set['seo']['title_delimiter'];
    if ($set['seo']['titlestyle'] == 'site_title') {
      $title = get_bloginfo('name') . $delimiter . get_the_title();
    } elseif ($set['seo']['titlestyle'] == 'title_site') {
      $title = get_the_title() . $delimiter . get_bloginfo('name');
    } else {
      $title = get_the_title();
    }
  } else {
    $title = get_the_title();
  }
} elseif (is_category()) {
  $catid = corepress_get_current_category_id();
  $cat_seo = get_option('corepress_cat_set_' . $catid);
  if ($set['seo']['catseo'] == 1) {
    if ($cat_seo['title'] == '') {
      $title = single_cat_title('', false);
    } else {
      $title = $cat_seo['title'];
    }
  } else {
    $title = single_cat_title('', false);
  }
} elseif (is_tag()) {
  $delimiter = $set['seo']['title_delimiter'];
  if ($set['seo']['openseo'] == 1) {
    if ($set['seo']['titlestyle'] == 'site_title') {
      $title = get_bloginfo('name') . $delimiter . single_cat_title('', false);
    } elseif ($set['seo']['titlestyle'] == 'title_site') {
      $title = single_cat_title('', false) . $delimiter . get_bloginfo('name');
    } else {
      $title = single_cat_title('', false);
    }
  } else {
    $title = single_cat_title('', false);
  }
} elseif (is_author()) {
  $delimiter = $set['seo']['title_delimiter'];
  if ($set['seo']['openseo'] == 1) {
    if ($set['seo']['titlestyle'] == 'site_title') {
      $title = get_bloginfo('name') . $delimiter . get_the_author() . '的文章';
    } elseif ($set['seo']['titlestyle'] == 'title_site') {
      $title = get_the_author() . '的文章' . $delimiter . get_bloginfo('name');
    } else {
      $title = get_the_author() . '的文章';
    }
  } else {
    $title = get_the_author() . '的文章';
  }
} elseif (is_search()) {
  $title = '搜索结果';
} else {
  if ($set['seo']['openseo'] == 1) {
    $delimiter = $set['seo']['title_delimiter'];
    $title = wp_title($delimiter, false, 'right');
  } else {
    $title = wp_title('&raquo;', false, 'right');
  }
}

echo "<title>{$title}</title>";
$keywords = '';
$description = '';
if (is_home()) {
  if ($set['seo']['description'] != null) {
    $description = $set['seo']['description'];
  } else {
    $description = get_bloginfo('description');
  }

  if ($set['seo']['keyword'] != null) {
    $keywords = $set['seo']['keyword'];
  }
} else if (is_single() || is_page()) {
  global $post;
  global $corepress_post_meta;
  $corepress_post_meta = json_decode(get_post_meta($post->ID, 'corepress_post_meta', true), true);
  if (empty($corepress_post_meta['seo']['open'])) {
    $corepress_post_meta['seo']['open'] = 0;
  }
  if (empty($corepress_post_meta['closesidebar'])) {
    $corepress_post_meta['closesidebar'] = 0;
  }
  if (empty($corepress_post_meta['postrighttag']['open'])) {
    $corepress_post_meta['postrighttag']['open'] = 0;
  }
  if (empty($corepress_post_meta['catalog'])) {
    $corepress_post_meta['catalog'] = 0;
  }

  if ($corepress_post_meta['seo']['open'] == 1) {
    $description = $corepress_post_meta['seo']['description'];
    $keywords = $corepress_post_meta['seo']['keywords'];
  } else {
    // 检测是否有手动摘要
    if (has_excerpt()) {
      $description = get_the_excerpt($post);
    } else {
      $description = str_replace('\n', '', mb_strimwidth(strip_tags($post->post_content), 0, 200, '…', 'utf-8'));
    }
    $tags = wp_get_post_tags($post->ID);
    foreach ($tags as $tag) {
      $keywords = $keywords . ', ' . $tag->name;
    }
    $keywords = ltrim($keywords, ', ');
  }
} elseif (is_tag()) {
  // 标签的description可以到后台 - 文章 - 标签，修改标签的描述
  $description = tag_description();
  $keywords = single_tag_title('', false);
} elseif (is_category()) {
  $catid = corepress_get_current_category_id();
  $cat_seo = get_option('corepress_cat_set_' . $catid);
  if ($cat_seo['description'] == '') {
    $description = category_description();
  } else {
    $description = $cat_seo['description'];
  }
  if ($cat_seo['keywords'] == '') {
    $keywords = single_tag_title('', false);
  } else {
    $keywords = $cat_seo['keywords'];
  }
  if ($set['seo']['openseo'] != 1) {
    if ($set['seo']['catseo'] == 1) {
?>
  <meta name="keywords" content="<?php echo $keywords; ?>" />
  <meta name="description" content="<?php echo $description; ?>" />
<?php
    }
  }
}
$description = trim(strip_tags($description));
$keywords = trim(strip_tags($keywords));
if ($set['seo']['openseo'] == 1) {
  if (post_password_required() == false) {
?>
  <meta name="keywords" content="<?php echo $keywords; ?>" />
  <meta name="description" content="<?php echo $description; ?>" />
<?php
  }
}
?>